package com.jiantong.work.impl.service.yangzhibaoxian;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.yangzhibaoxian.ClaimsResultDao;
import com.jiantong.work.impl.dao.yangzhibaoxian.InsuranceApplicationDao;
import com.jiantong.work.model.yangzhibaoxian.ClaimsLoss;
import com.jiantong.work.model.yangzhibaoxian.ClaimsResult;
import com.jiantong.work.service.yangzhibaoxian.ClaimsResultService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.PageInfo;
import io.terminus.common.model.Paging;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by ThinkPad on 2017/9/5.
 */

/**
 * 理赔结果
 */
@Slf4j
@Service
@RpcProvider
public class ClaimsResultServiceImpl implements ClaimsResultService{
    private ClaimsResultDao claimsResultDao;

    @Autowired
    public ClaimsResultServiceImpl(ClaimsResultDao claimsResultDao) {
        this.claimsResultDao = claimsResultDao;
    }

    @Override
    public Response<ClaimsResult> findById(Long id) {
        try {
            ClaimsResult claimsResult = (ClaimsResult) claimsResultDao.findById(id);
            if (claimsResult == null) {
                log.error("claimsLoss(id={}) is not found", id);
                return Response.fail("claimsLoss.not.found");
            }

            return Response.ok(claimsResult);
        } catch (Exception e) {
            log.error("failed to find claimsLoss(id={}), cause:{}", id, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsLoss.find.fail");
        }
    }

    @Override
    public Response<List<ClaimsResult>> findByIds(List ids) {
        try {
            List<ClaimsResult> claimsResultList=  claimsResultDao.findByIds(ids);
            if (claimsResultList == null) {
                log.error("claimsResultList(ids={}) is not found", ids);
                return Response.fail("claimsResultList.not.found");
            }

            return Response.ok(claimsResultList);
        } catch (Exception e) {
            log.error("failed to find claimsResultList(ids={}), cause:{}", ids, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsResultList.find.fail");
        }

    }

    @Override
    public Response<List<ClaimsResult>> list(Map map) {
        try {
            List<ClaimsResult> claimsResultList=  claimsResultDao.list(map);
            if (claimsResultList == null) {
                log.error("claimsResultList(ids={}) is not found", map);
                return Response.fail("claimsResultList.not.found");
            }

            return Response.ok(claimsResultList);
        } catch (Exception e) {
            log.error("failed to find claimsResultList(ids={}), cause:{}", map, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsResultList.find.fail");
        }
    }

    @Override
    public Response<Paging<ClaimsResult>> ping(Integer offset, Integer limit, Map map) {
        try {
            PageInfo pageInfo=new PageInfo(offset,limit);
            Paging<ClaimsResult> claimsLossPaging=  claimsResultDao.paging(pageInfo.getOffset(),pageInfo.getLimit() ,map);
            if (claimsLossPaging == null) {
                log.error("claimsLossPaging(ids={}) is not found", map);
                return Response.fail("claimsLossPaging.not.found");
            }

            return Response.ok(claimsLossPaging);
        } catch (Exception e) {
            log.error("failed to find bankcardList(ids={}), cause:{}", map, Throwables.getStackTraceAsString(e));
            return Response.fail("claimsLossPaging.find.fail");
        }
    }

    @Override
    public Boolean update(ClaimsResult claimsResult) {
        try {
            Boolean b=claimsResultDao.update(claimsResult);
            return b;
        }catch (Exception e){
            return false;
        }
    }

    @Override
    public Long create(ClaimsResult claimsResult) {
        try {
            claimsResultDao.create(claimsResult);
            return claimsResult.getId();
        }catch (Exception e){
            e.printStackTrace();
            return -500L;
        }
    }

    @Override
    public Integer creates(List<ClaimsResult> claimsResultList) {
        try {

            return  claimsResultDao.creates(claimsResultList);
        }catch (Exception e){
            e.printStackTrace();
            return -500;
        }
    }

    @Override
    public ClaimsResult findByClaimsId(Long claims_settlement_id) {
        return claimsResultDao.findByClaimsId(claims_settlement_id);
    }

}
